package com.example.zzpneo4j.dto;

import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.Setter;

import java.io.Serializable;

/**
 * 失败的
 *
 * @param <T>
 */
@Getter
@Setter
@AllArgsConstructor
public class Result<T> implements Serializable {

    public static final int SUCCESS_CODE = 0;
    public static final int FAILURE_CODE = 500;
    public static final String SUCCESS_MSG = "请求成功！";
    public static final String FAILURE_MSG = "请求失败！";

    private int code;
    private T data;
    private String message;
    /**
     * null时不返回
     */
    @JsonInclude(value = JsonInclude.Include.NON_NULL)
    private String token;

    public Result(int code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public Result(int code, String message) {
        this.message = message;
        this.code = code;
    }

    public Result(int code) {
        this.code = code;
    }

    public Result(int code, String data, Long num, String message) {
        this.data = (T) data;
        this.code = code;
        this.message = message;
    }

    public Result(int code, String data, Integer num) {
        this.data = (T) data;
        this.code = code;
    }

    public static Result success(Object data) {
        return new Result(SUCCESS_CODE, SUCCESS_MSG, data);
    }

    public static Result success(String msg) {
        return new Result(SUCCESS_CODE, msg);
    }

    public static Result success(String msg, Boolean b) {
        return new Result(SUCCESS_CODE);
    }

    public static Result successString(Integer code, String data, Long num) {
        return new Result(code, data, num);
    }

    public static Result successString(Integer code, String data, Long num, String msg) {
        return new Result(code, data, num, msg);
    }

    public static Result fail(Object data) {
        return new Result(FAILURE_CODE, FAILURE_MSG, data);
    }

    public static Result fail(String msg) {
        return new Result(FAILURE_CODE, msg);
    }

    public static Result fail(int code, String msg) {
        return new Result(code, msg);
    }

    public static Result success() {
        return success(null);
    }

    public static Result fail() {
        return fail(null);
    }


}
